package io.kiki.sba.registry.common.model.slot.filter;

import java.util.Collections;
import java.util.Optional;
import java.util.Set;


public class BaseSyncSlotAcceptorManager implements SyncSlotAcceptorManager {

    protected final Set<SyncSlotAcceptor> set;

    public BaseSyncSlotAcceptorManager(Set<SyncSlotAcceptor> set) {
        this.set = set;
    }

    public boolean accept(SyncAcceptorRequest request) {

        for (SyncSlotAcceptor syncSlotAcceptor : Optional.ofNullable(set).orElse(Collections.emptySet())) {
            if (syncSlotAcceptor.filterOut(request)) {
                return false;
            }
        }
        for (SyncSlotAcceptor syncSlotAcceptor : Optional.ofNullable(set).orElse(Collections.emptySet())) {
            if (syncSlotAcceptor.accept(request)) {
                return true;
            }
        }
        return false;
    }
}
